package cn.yeziji.forum.vo.details;

import cn.yeziji.forum.entity.ForumDetailsEntity;
import cn.yeziji.forum.utils.StrUtils;
import lombok.Data;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

/**
 * 文章返回对象
 *
 * @author gzkemays
 * @since 2021/12/23 23:04
 */
@Data
public class DetailVO {
  Integer id;
  Integer userId;
  /** 作者简介 */
  String authorDesc;
  /** 作者头像 */
  String avatar;
  /** 发布时间 */
  String publishTime;
  /** 专栏 */
  String special;
  /** details default attribute */
  String author;

  Long serialNumber;
  Long view;
  String title;
  String content;
  String desc;
  String tags;
  Integer goodNumber;
  Integer commentNumber;
  Integer collectionNumber;
  String aveRate;
  Boolean autoFormat;
  Boolean tempSave;
  Boolean toCollection;
  Boolean toComment;
  Boolean toGood;
  Boolean toRecovery;
  BigDecimal toRate;
  List<DetailSpecialVO> specialVOS;

  public static String dateFormat(ForumDetailsEntity entity) {
    Date updateTime = entity.getUpdateTime();
    if (updateTime == null) {
      return StrUtils.dateToStr("yyyy-MM-dd", entity.getCreateTime());
    }
    return StrUtils.dateToStr("yyyy-MM-dd", updateTime);
  }

  public static String dateFormat(Date date) {
    if (date == null) {
      throw new RuntimeException("日期为空");
    }
    return StrUtils.dateToStr("yyyy-MM-dd", date);
  }

  public void defaultOperation() {
    this.setToCollection(false);
    this.setToComment(false);
    this.setToGood(false);
    this.setToRate(BigDecimal.ZERO);
  }

  public void additionView() {
    this.view++;
  }
}
